<template>
  <view class="login-container">
    <custom-nav-bar title="房东登录" />
    
    <view class="form-wrapper">
      <uni-forms ref="formRef">
        <uni-forms-item label="账号" name="username">
          <uni-easyinput v-model="formData.username" placeholder="请输入账号" />
        </uni-forms-item>
        
        <uni-forms-item label="密码" name="password">
          <uni-easyinput type="password" v-model="formData.password" placeholder="请输入密码" />
        </uni-forms-item>
        
        <button class="submit-btn" @click="handleSubmit">登录</button>
      </uni-forms>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { loginLandlord } from '@/api/authApi'

const formRef = ref()
const formData = ref({
  username: '',
  password: ''
})

const handleSubmit = async () => {
  try {
    const valid = await formRef.value.validate()
    if (valid) {
      await loginLandlord(formData.value)
      uni.reLaunch({ url: '/pages/admin/house-list/index' })
    }
  } catch (err) {
    uni.showToast({ title: '登录失败', icon: 'none' })
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  height: 100vh;
  display: flex;
  flex-direction: column;

  .form-wrapper {
    flex: 1;
    padding: 60rpx;
    
    .submit-btn {
      margin-top: 60rpx;
      height: 80rpx;
      line-height: 80rpx;
      background: #2979FF;
      color: #fff;
      border-radius: 40rpx;
      font-size: 28rpx;
    }
  }
}
</style>